package production.practice.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import production.practice.pojo.dto.UserDTO;
import production.practice.pojo.entity.User;
import production.practice.pojo.fuction.result.PageResult;
import production.practice.pojo.fuction.result.Result;
import production.practice.service.UserService;
import production.practice.utils.BinaryUtils;

@RestController
@RequestMapping("/admin/user")
@Api(tags ="用户接口")
public class UserController {
    @Autowired
    UserService userService;


    @ApiOperation("用户登录")
    @PostMapping("/login")
    public Result<String> login(@RequestBody String body) {
        String token = userService.login(body);
        return BinaryUtils.isNotEmpty(token)? Result.success(token) : Result.error("登录失败,请检查账号密码");
    }

    @ApiOperation("分页查询用户")
    @GetMapping("/list")
    public Result<PageResult<User>> getAllUser(UserDTO userDTO) {
        return Result.success();
    }

    @ApiOperation("添加或者修改用户")
    @PostMapping("/save")
    public Result save(@RequestBody User user) {

        return Result.success();
    }

    @ApiOperation("删除用户")
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        return Result.success();
    }


}
